<?php
class Arisan_model extends CI_Model{

	function   __construct() {
        parent::__construct();
        
    }
//page
	private $tbl = 'arisan';

	function selectAll()
	{
		return $this->db->get($this->tbl)->result();
	}
		
	function get_list_data($limit = 10, $offset = 0) 
  	{
		  if($offset==""){ $offset=0; }
	$query = $this->db->query("SELECT a.*, b.strnama,c.strwilayah
            FROM arisan a, barang b , wilayah c
            WHERE a.intid_barang=b.intid_barang
            AND a.intid_wilayah = c.intid_wilayah
            ORDER BY intid_arisan ASC LIMIT $offset,$limit");
        return $query->result();
  	}
	
	function countData() 
	{   
	  	return $this->db->count_all($this->tbl);
  	}
//end page
   function selectWilayah(){

	   $query = $this->db->query("select * from wilayah order by intid_wilayah asc");
	   return $query->result();
    }

    function selectDetail($intid_arisan){
       $query = $this->db->query("SELECT a.*, b.strnama,c.strwilayah
            FROM arisan a, barang b, wilayah c
            WHERE a.intid_barang=b.intid_barang and
               a.intid_wilayah=c.intid_wilayah and
               a.intid_arisan= '$intid_arisan'");
	   return $query->result();
    }
    
    function getSearch($q)
    {
        $sql="SELECT a.*, b.strnama,b.intharga_luarjawa, b.intharga_jawa
FROM arisan a, barang b
WHERE b.strnama like '$q%";
        $q = $this->db->query($sql);
        return $q;
    }
    function insert($data){
	$data = array(
            'intid_barang' => $this->input->post('id_barang'),
            'intcicilan' => $this->input->post('intcicilan'),
            'intuang_muka' => $this->input->post('intuang_muka'),
            'intuang_cicilan' => $this->input->post('intuang_cicilan'),
            'intid_wilayah' => $this->input->post('intid_wilayah'),
            'intharga_arisan' => $this->input->post('intharga_arisan')
           // 'intkomisi' => $this->input->post('intkomisi')
                );
        $this->db->insert('arisan', $data);
	}

   function delete($idarisan){
       $this->db->where('intid_arisan', $idarisan);
       $this->db->delete('arisan');
    }

    function selectBarang($keyword){
        $query = $this->db->query("select a.intid_barang, upper(strnama) strnama, intharga_jawa, intharga_luarjawa
                from barang a left join arisan b
                on a.intid_barang = b. intid_barang
                where strnama like '$keyword%'");
        return $query->result();
	}

//     function selectBarangArisan($keyword){
//        $query = $this->db->query("select b.intid_barang, upper(strnama) strnama, intharga_jawa, intharga_luarjawa,intcicilan,intuang_muka
//                from barang a right join arisan b
//                on a.intid_barang = b. intid_barang
//                where strnama like '$keyword%'");
//        return $query->result();
//	}

        function selectPeserta($keyword){
         $query = $this->db->query("select intid_dealer,upper(strnama_dealer) strnama_dealer from member  where intid_dealer = $keyword");
         return $query->result();
	}
//     function selectBarang($keyword){
//        $query = $this->db->query("select a.intid_barang, upper(strnama) strnama, intharga_jawa, intharga_luarjawa
//                from barang a left join arisan b
//                on a.intid_barang = b. intid_barang
//                where strnama like '$keyword%'");
//        //$query = $this->db->query("select intid_barang, upper(strnama) strnama, intharga_jawa, intharga_luarjawa from barang where strnama like '$keyword%'");
//       // $query = $this->db->query("select intid_barang, upper(strnama) strnama, intharga_jawa, intharga_luarjawa from promo10 where strnama like '$keyword%'");
//        return $query->result();
//	}
    function select($idarisan){
       $query = $this->db->query("select * from arisan where intid_arisan= $idarisan");
	   return $query->result();
    }

	function update($idarisan){
           $data = array(
            'intid_barang' => $this->input->post('intid_barang'),
            'intcicilan' => $this->input->post('intcicilan'),
            'intuang_cicilan' => $this->input->post('intuang_cicilan'),
            'intuang_muka' => $this->input->post('intuang_muka'),
            'intid_wilayah' => $this->input->post('intid_wilayah'),
            'intharga_arisan' => $this->input->post('intharga_arisan')
           // 'intkomisi' => $this->input->post('intkomisi')
                );
            $this->db->where('intid_arisan', $idarisan);
            $this->db->update('arisan',$data);
    }

    function lookup($keyword){
	$this->db->select('*')->from('barang');
        $this->db->like('strnama',$keyword,'after');
        $query = $this->db->get();
      //  $query = $this->db->query("select * from barang order by intid_barang asc");
        return $query->result();
	}

}
?>
